/**
 * All Rights Reserved , Copyright (C) 2021 , 青岛鼎信通讯股份有限公司
 *
 *SdProjectSuperviseController
 * SD项目督办
 *
 * 修改纪录
 * 2021-12-08 版本：1.0 wangxinhua 创建。
 * @version 版本：1.0
 * @author 作者：wangxinhua
 * 创建日期：2021-12-08
 */

package com.topscomm.gpm.controller;

import java.util.Date;
import java.util.Map;

import com.topscomm.gpm.controller.auto.GpmProjectSuperviseControllerAuto;
import com.topscomm.pub.util.DateUtil;
import com.topscomm.gpm.service.impl.GpmProjectSuperviseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.topscomm.pub.util.StringBufferProxy;
import com.topscomm.pub.util.StringUtil;
import com.topscomm.pub.vo.ResponseResult;

/**
 * @author: wangxinhua
 * @date: 2021-12-08
 * @description:SD项目督办Controller
 * @modify:
 */
@RestController
@RequestMapping("sd/projectSupervise")
public class GpmProjectSuperviseController extends GpmProjectSuperviseControllerAuto implements IGpmProjectSuperviseController {
	@Autowired
	private GpmProjectSuperviseService gpmProjectSuperviseService;
	/**
	 * @author: wangxinhua
	 * @date: 2021-12-08
	 * @param paraMap
	 * @return
	 * @description:转换出查询SQL语句
	 * @modify:
	 */
	@Override
	protected String spellListSql(Map<String, Object> paraMap) {
		StringBufferProxy sql = new StringBufferProxy();
		sql.appendSingle(" 1=1 ");
		if (paraMap.containsKey("qry_supervisename")) {
			String value = paraMap.get("qry_supervisename").toString();
			if (!StringUtil.isEmpty(value))
				sql.appendSingle(" and supervisename like '%{0}%' ", value);
		}
		if (paraMap.containsKey("qry_superviseobjecttype")) {
			String value = paraMap.get("qry_superviseobjecttype").toString();
			if (!StringUtil.isEmpty(value))
				sql.appendSingle(" and superviseobjecttype = '{0}'", value);
		}
		if (paraMap.containsKey("qry_projectid")) {
			String value = paraMap.get("qry_projectid").toString();
			if (!StringUtil.isEmpty(value)) {
				sql.appendSingle(" and projectid = '{0}'", value);
			}
		}
		return sql.toString();
	}

	/**
	 * @author: wangxinhua
	 * @date: 2021-12-08
	 * @param paraMap
	 * @return
	 * @description:转换出查询SQL语句
	 * @modify:
	 */
	@Override
	@GetMapping(value = "/refList")
	public ResponseResult<Object> refList(@RequestParam(required = false) Map<String, Object> paraMap) {
		return super.refList(paraMap);
	}

	/**
	 * @author: zhangjunyao
	 * @date: 2021-12-16
	 * @param paraMap, dataMap
	 * @return
	 * @description:提交审批前
	 * @modify:
	 */
	@Override
	protected void beforeSubmit(Map<String, Object> dataMap, Map<String, Object> paraMap) throws Exception {
		super.beforeSubmit(dataMap, paraMap);
		StringBufferProxy mailtitle = new StringBufferProxy();
		mailtitle.appendSingle("{0}{1}于{2}提交项目督办申请,单据编号{3}! ", dataMap.get("deptname"), dataMap.get("username"),
				DateUtil.dateToString(new Date(), "yyyy-MM-dd"), dataMap.get("docno"));
		dataMap.put("maintitle", mailtitle.toString());
	}
	/***
	 * @description: 项目立项变更
	 * @param paraMap
	 * @return
	 * @author: houyuhang
	 * @date:
	 **/
	@PutMapping(value = "/updateSuperviseUser")
	public ResponseResult<Object> updateSuperviseUser(@RequestBody(required = false) Map<String, Object> paraMap) {
		try {
			gpmProjectSuperviseService.updateSuperviseUser(paraMap);
			return ResponseResult.ok("更新成功");
		} catch (Exception ex) {
			return handleControllerException(ex);
		}
	}

}

